import BaseListItem from '../base/BaseListItem.js';
import Common from "../../common/common.js";
import {AddFriendRemarkWin} from './FriendWin.js';
import TimNet from '../../timnet.js';

//寄生组合式继承
function UserListItem () {
    BaseListItem.call(this,{});
}
let prototype = Object.create(BaseListItem.prototype);
prototype.constructor = UserListItem;
UserListItem.prototype  = prototype;

//各个操作事件
UserListItem.prototype.bind = function(){
    Common.tool.addHandle(this.element,"click",()=>{
        new AddFriendRemarkWin(this).create();
    });
}

//设置数据
UserListItem.prototype.setData = function(data){
    this.data = data;
    this.setAvatar(Common.tool.getAvatar(data.avatar));
    this.setName(Common.tool.isNull(data.nick)?data.userID:data.nick);
    this.setMsg(data.selfSignature);
}

//设置用户
UserListItem.prototype.updateDataByUserID = function(userID){
    //如果用户存在
    if(Common.cache.userInfo[userID]){
         this.setData(Common.cache.userInfo[userID]);
    }
    else
    {
        TimNet.getUserProfile([userID],(d)=>{
            if(d && d[0]){
                Common.cache.userInfo[userID] = d[0];
                 this.setData(Common.cache.userInfo[userID]);
            };
        })
    }
    return this;
}



export default UserListItem
